import req from "../utils/http.js"

//  获取登录
export function getLogin(username, password, rememberMe = true) {
    let params = new URLSearchParams();
    params.append("username", username);
    params.append("rememberMe", rememberMe);
    params.append("password", password);
    console.log(params.get("password"))
    return req.post(`/api/login`, params)
}

//  获取注册
export function getRegistered(loginName, code, phonenumber, password, userName, sex) {
    let params = new URLSearchParams()
    params.append("loginName", loginName)    //账号
    params.append("code", code)              //短信验证码
    params.append("phonenumber", phonenumber)//电话号码
    params.append("password", password)      //密码
    params.append("userName", userName)      //昵称
    params.append("sex", sex)                //性别0男1女    非必须
    return req.post(`/api/registry`, params)
}

//  获取验证码
export function getVerificationCode(mobile) {
    return req.get(`/api/short-message/vcode/${mobile}`)
}

//  查看个人信息
export function getPersonalInformation() {
    return req.get(`/api/login-user/info`)
}

//  退出登录
export function getLogOut() {
    return req.get(`/api/logout`)
}

//  忘记密码
export function postForgotPassword(loginName, password, phonenumber, code) {
    let params = new URLSearchParams()
    params.append("loginName", loginName)
    params.append("password", password)
    params.append("phonenumber", phonenumber)
    params.append("code", code)
    return req.post(`/api/password/forget`, params)
}

//  修改个人信息
export function postEditData(userName, email, phonenumber, sex, remark) {
    let params = new URLSearchParams()
    params.append("userName", userName)
    params.append("email", email)
    params.append("phonenumber", phonenumber)
    params.append("sex", sex)
    params.append("remark", remark)
    return req.post(`/api/system/user/profile/update`, params)
}

// 修改头像
export function postHeadPortrait(avatarfile) {
    let params = new URLSearchParams()
    params.append("avatarfile", avatarfile)
    return req.post(`/api/system/user/profile/update/avatar/nos`, params)
}

export function changeImg(file) {
    const formData = new FormData();
    formData.append("avatarfile", file);
    return req.post('/api/system/user/profile/update/avatar/nos', formData)
}

//  获取全部mv
export function getMV(area = " ", type = " ", order = " ") {
    //
    return req.get(`/music-api/mv/all?area=${area}&type=${type}&order=${order}&limit=20`)

}
//  获取 mv 数据
export function getMVData(mvid){
    return req.get(`/music-api/mv/detail?mvid=${mvid}`)
}
//  mv 地址
export function getMVUrl(id,r=240){
    return req.get(`/music-api/mv/url?id=${id}&r=${r}`)
}

//  mv评论
export function getMVcomments(id){
    return req.get(`/music-api/comment/mv?id=${id}`)
}

//  收藏/取消收藏 MV
// export function getSubMV(mvid,t){
//     return req.get(`/music-api/mv/sub?id=${mvid}&t=${t}`)
// }